---
title: "Political violence report"
author: "Benedetta Giocoli"
date: "24/01/2022"
output:
  html_document:
    df_print: paged
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## Setup
```{r load packages}
# Load packages
library(tidyverse)
library(ggplot2)
library(stats)
library(gmodels)
library(vcd)
library(grid)
library(jtools)
library(huxtable)
library(flextable)
```

## Tidy data
```{r tidy data}
## Load data
data <- read.csv('PoliticalViolence.csv')

## Rename columns
names(data) <- c('ID', 'weight_pol', 'start_time', 'end_time', 'age', 'gender', 'region', 'race', 'education', 'marital_status', 'parent_yes_u18', 'parent_yes_o18', 'parent_no', 'parent_idk', 'gross_household_income', 'gross_household_income_grouped', 'political_party', 'political_ideology', 'past_vote', 'scenario_type', 'moral_legitimacy', 'strategic_legitimacy', 'terrorism')

## Recode variables of interest 
# gender
data$gender <- recode(data$gender,
                      `1` = 'Male',
                      `2` = 'Female'
)

# race
data$race <- recode_factor(data$race,
                           `1` = 'White',
                           `2` = 'Black',
                           `3` = 'Hispanic',
                           `4` = 'Other (NET)'
)

# scenario_type
data$scenario_type <- recode(data$scenario_type,
                             `1` = 'Pro abortion, no injuries', 
                             `2` = 'Pro abortion, casualties', 
                             `3` = 'Anti abortion, no injuries', 
                             `4` = 'Anti abortion, casualties', 
                             `5` = 'Pro environment, no injuries', 
                             `6` = 'Pro environment, casualties', 
                             `7` = 'Anti environment, no injuries', 
                             `8` = 'Anti environment, casualties', 
                             `9` = 'Pro immigration, no injuries', 
                             `10` = 'Pro immigration, casualties', 
                             `11` = 'Anti immigration, no injuries', 
                             `12` = 'Anti immigration, casualties'
)

# political_party
data$political_party <- recode_factor(data$political_party, 
                                      `1` = 'Democrat', 
                                      `2` = 'Republican', 
                                      `3` = 'Independent', 
                                      `4` = "Prefer not to say", 
                                      `5` = 'Not sure'
)

# political_ideology
data$ideology <- recode_factor(data$political_ideology, 
                                         `1` = 'Very liberal', 
                                         `2` = 'Liberal', 
                                         `3` = 'Moderate', 
                                         `4` = 'Conservative', 
                                         `5` = 'Very conservative', 
                                         `6` = 'Not sure'
)

# moral_legitimacy (recode on a -3 to 3 scale)
data$moral_legitimacy = -1*(data$moral_legitimacy - 4)

# strategic_legitimacy (recode on a -3 to 3 scale)
data$strategic_legitimacy = -1*(data$strategic_legitimacy - 4)

# terrorism (recode on a -3 to 3 scale)
data$terrorism = -1*(data$terrorism - 4)
```


## EFFECT OF POLITICAL PARTY AFFILIATION
# Effect of political party affiliation in general
```{r regression for legitimacy}
# Moral legitimacy
regression_party_moral <- lm(moral_legitimacy ~ political_party, data = data, weights = weight_pol)
summary(regression_party_moral)

# Strategic legitimacy
regression_party_strategic <- lm(strategic_legitimacy ~ political_party, data = data, weights = weight_pol)
summary(regression_party_strategic)

# Terrorism
regression_party_terrorism <- lm(terrorism ~ political_party, data = data, weights = weight_pol)
summary(regression_party_terrorism)
```

## Plots
```{r regression plots}
# Regression plots
export_summs(regression_party_moral, regression_party_strategic, regression_party_terrorism, model.names = c('Moral legitimacy', 'Strategic legitimacy', 'Terrorism perception'), scale = TRUE, to.file = 'pdf')

# Density plots
# Moral legitimacy
ggplot(data, aes(x=moral_legitimacy, colour=political_party)) + labs(x='Moral legitimacy score', y='Density', colour='Political Party') + ggtitle('Density plot') + geom_density()
ggsave('Moral legitimacy density plot.pdf', scale = 2)

# Strategic legitimacy
ggplot(data, aes(x=strategic_legitimacy, colour=political_party)) + labs(x='Strategic legitimacy score', y='Density', colour='Political Party') + ggtitle('Density plot') + geom_density()
ggsave('Strategic legitimacy density plot.pdf', scale = 2)

# Terrorism
ggplot(data, aes(x=terrorism, colour=political_party)) + labs(x='Terrorism score', y='Density', colour='Political Party') + ggtitle('Density plot') + geom_density()
ggsave('Terrorism perception density plot.pdf', scale = 2)
```

## Analysis setup
```{r analysis setup}
# Collapse scenarios
data1 <- data

data1$scenario_type <- recode(data1$scenario_type,
                             'Pro abortion, no injuries' = 'Pro abortion', 
                             'Pro abortion, casualties' = 'Pro abortion', 
                             'Anti abortion, no injuries' = 'Anti abortion', 
                             'Anti abortion, casualties' = 'Anti abortion', 
                             'Pro environment, no injuries' = 'Pro environment', 
                             'Pro environment, casualties' = 'Pro environment', 
                             'Anti environment, no injuries' = 'Anti environment', 
                             'Anti environment, casualties' = 'Anti environment', 
                             'Pro immigration, no injuries' = 'Pro immigration', 
                             'Pro immigration, casualties' = 'Pro immigration', 
                             'Anti immigration, no injuries' = 'Anti immigration', 
                             'Anti immigration, casualties' = 'Anti immigration')

# Create subsetting function
subset1 <- function(x){
  data1[grepl(x, data1$scenario_type), ]}
```

## Moral legitimacy
```{r moral legitimacy}
# Create linear regression function
lr1 <- function(x){
  lm(moral_legitimacy ~ political_party, data = x, weights = weight_pol)}

# Pro abortion
data_p_abortion <- subset1("Pro abortion")
model_p_abortion <- lr1(data_p_abortion)
summary(model_p_abortion) ## Significant for Republicans, Independents, and Not sure

# Anti abortion
data_a_abortion <- subset1("Anti abortion")
model_a_abortion <- lr1(data_a_abortion)
summary(model_a_abortion) ## Significant for Not sure

# Pro environment
data_p_environment <- subset1("Pro environment")
model_p_environment <- lr1(data_p_environment)
summary(model_p_environment) # Significant for Not sure

# Anti environment
data_a_environment <- subset1("Anti environment")
model_a_environment <- lr1(data_a_environment)
summary(model_a_environment) ## Significant for Republicans and Not sure

# Pro immigration
data_p_immigration <- subset1("Pro immigration")
model_p_immigration <- lr1(data_p_immigration)
summary(model_p_immigration) ## Significant for Republicans and Not sure

# Anti immigration
data_a_immigration <- subset1("Anti immigration")
model_a_immigration <- lr1(data_a_immigration)
summary(model_a_immigration) ## Significant for Independents and Not sure

# Regression plots
export_summs(model_p_abortion, model_a_abortion, model_p_environment, model_a_environment, model_p_immigration, model_a_immigration, model.names = c('Pro-abortion target', 'Anti-abortion target', 'Pro-environment target', 'Anti-environment target', 'Pro-immigration target', 'Anti-immigration target'), to.file = 'html', scale = TRUE)
```

## Terrorism
```{r terrorism}
# Create linear regression function
lr2 <- function(x){
  lm(terrorism ~ political_party, data = x, weights = weight_pol)}

# Pro abortion
# Linear regression
model_p_abortion <- lr2(data_p_abortion)
summary(model_p_abortion) ## Significant for Republicans, Independents, and Not sure

# Anti abortion
# Linear regression
model_a_abortion <- lr2(data_a_abortion)
summary(model_a_abortion) ## Significant for all

# Pro environment
# Linear regression
model_p_environment <- lr2(data_p_environment)
summary(model_p_environment) # Significant for all

# Anti environment
# Linear regression
model_a_environment <- lr2(data_a_environment)
summary(model_a_environment) ## Significant for Not sure

# Pro immigration
# Linear regression
model_p_immigration <- lr2(data_p_immigration)
summary(model_p_immigration) ## Significant for Independents and Not sure

# Anti immigration
# Linear regression
model_a_immigration <- lr2(data_a_immigration)
summary(model_a_immigration) ## Significant for Independents, Prefer not to say, and Not sure

# Regression plots
export_summs(model_p_abortion, model_a_abortion, model_p_environment, model_a_environment, model_p_immigration, model_a_immigration, model.names = c('Pro-abortion target', 'Anti-abortion target', 'Pro-environment target', 'Anti-environment target', 'Pro-immigration target', 'Anti-immigration target'), to.file = 'html', scale = TRUE)
```

## Political party and ideology
```{r political party and ideology}
# Create scatter plot for visual inspection
party_vs_ideology <- ggplot(data, aes(x=political_party, y=political_ideology)) +
  geom_point(alpha=.2, position='jitter', colour='black') + xlab('Political party') +
  ylab('Political ideology') + ggtitle('Party vs ideology')
ggsave('Party vs ideology.pdf', scale = 2)

# Create cross-tabulation
cross_tabulation <- with(data, CrossTable(political_party, political_ideology, expected=TRUE, prop.c=FALSE, prop.t=FALSE, format=c('SPSS')))   

# Assess the strength of the relationship
# Create contingency table
contingency_table <- table(data$political_ideology, data$political_party)
# Run Cramer's V
assocstats(contingency_table)
```


## EFFECT OF IDEOLOGY
# Effect of ideology in general (non-issue-oriented)
```{r effect of ideology, non-issue-oriented regressions}
# Determine appropriate regression benchmark
summary(data$ideology)

# Run linear regression for moral legitimacy
regression_ideology_moral <- lm(moral_legitimacy ~ relevel(ideology, "Moderate"), data = data, weights = weight_pol)
summary(regression_ideology_moral)

# Run linear regression for strategic legitimacy
regression_ideology_strategic <- lm(strategic_legitimacy ~ relevel(ideology, "Moderate"), data = data, weights = weight_pol)
summary(regression_ideology_strategic)

# Run linear regression for terrorism
regression_ideology_terrorism <- lm(terrorism ~ relevel(ideology, "Moderate"), data = data, weights = weight_pol)
summary(regression_ideology_terrorism)

# Regression plots
export_summs(regression_ideology_moral, regression_ideology_strategic, regression_ideology_terrorism, model.names = c('Moral legitimacy', 'Strategic legitimacy', 'Terrorism perception'), scale = TRUE, to.file = 'pdf')

## Density plots
# Moral legitimacy
ggplot(data, aes(x=moral_legitimacy, colour=ideology)) + labs(x='Moral legitimacy score',
                                                                 y='Density', colour='Ideology') + ggtitle('Density plot') + geom_density()
ggsave('Moral legitimacy vs ideology density plot.pdf', scale = 2)

# Strategic legitimacy
ggplot(data, aes(x=strategic_legitimacy, colour=ideology)) + labs(x='Strategic legitimacy score',
                                                                 y='Density', colour='Ideology') + ggtitle('Density plot') + geom_density()
ggsave('Strategic legitimacy vs ideology density plot.pdf', scale = 2)

# Terrorism
ggplot(data, aes(x=terrorism, colour=ideology)) + labs(x='Terrorism score',
                                                                 y='Density', colour='Ideology') + ggtitle('Density plot') + geom_density()
ggsave('Terrorism perception vs ideology density plot.pdf', scale = 2)
```

# Effect of ideology on moral legitimacy (issue-oriented, irrespective of casualties)
```{r ideology on moral legitimacy}
# Create linear regression function
lr3 <- function(x){
  lm(moral_legitimacy ~ relevel(ideology, "Moderate"), data = x, weights = weight_pol)}

# Pro abortion
data_p_abortion <- subset1("Pro abortion")
# Linear regression
model_p_abortion1 <- lr3(data_p_abortion)
summary(model_p_abortion1)

# Anti abortion
data_a_abortion <- subset1("Anti abortion")
# Linear regression
model_a_abortion1 <- lr3(data_a_abortion)
summary(model_a_abortion1)

# Pro environment
data_p_environment <- subset1("Pro environment")
# Linear regression
model_p_environment1 <- lr3(data_p_environment)
summary(model_p_environment1)

# Anti environment
data_a_environment <- subset1("Anti environment")
# Linear regression
model_a_environment1 <- lr3(data_a_environment)
summary(model_a_environment1)

# Pro immigration
data_p_immigration <- subset1("Pro immigration")
# Linear regression
model_p_immigration1 <- lr3(data_p_immigration)
summary(model_p_immigration1)

# Anti immigration
data_a_immigration <- subset1("Anti immigration")
# Linear regression
model_a_immigration1 <- lr3(data_a_immigration)
summary(model_a_immigration1)

# Regression plots
export_summs(model_p_abortion1, model_a_abortion1, model_p_environment1, model_a_environment1, model_p_immigration1, model_a_immigration1, model.names = c('Pro-abortion target', 'Anti-abortion target', 'Pro-environment target', 'Anti-environment target', 'Pro-immigration target', 'Anti-immigration target'), to.file = 'html', scale = TRUE)
```

# Effect of ideology on strategic legitimacy (issue-oriented, irrespective of casualties)
```{r ideology on strategic legitimacy}
# Create linear regression function
lr4 <- function(x){
  lm(strategic_legitimacy ~ relevel(ideology, "Moderate"), data = x, weights = weight_pol)}

# Pro abortion
# Linear regression
model_p_abortion2 <- lr4(data_p_abortion)
summary(model_p_abortion2)

# Anti abortion
# Linear regression
model_a_abortion2 <- lr4(data_a_abortion)
summary(model_a_abortion2)

# Pro environment
# Linear regression
model_p_environment2 <- lr4(data_p_environment)
summary(model_p_environment2)

# Anti environment
# Linear regression
model_a_environment2 <- lr4(data_a_environment)
summary(model_a_environment2)

# Pro immigration
# Linear regression
model_p_immigration2 <- lr4(data_p_immigration)
summary(model_p_immigration2) 

# Anti immigration
# Linear regression
model_a_immigration2 <- lr4(data_a_immigration)
summary(model_a_immigration2)

# Regression plots
export_summs(model_p_abortion2, model_a_abortion2, model_p_environment2, model_a_environment2, model_p_immigration2, model_a_immigration2, model.names = c('Pro-abortion target', 'Anti-abortion target', 'Pro-environment target', 'Anti-environment target', 'Pro-immigration target', 'Anti-immigration target'), to.file = 'html', scale = TRUE)
```
 
# Effect of ideology on terrorism perception (issue-oriented, irrespective of casualties)
```{r ideology on perception as terrorism}
# Create linear regression function
lr5 <- function(x){
  lm(terrorism ~ relevel(ideology, "Moderate"), data = x, weights = weight_pol)}

# Pro abortion
# Linear regression
model_p_abortion3 <- lr5(data_p_abortion)
summary(model_p_abortion3)

# Anti abortion
# Linear regression
model_a_abortion3 <- lr5(data_a_abortion)
summary(model_a_abortion3)

# Pro environment
# Linear regression
model_p_environment3 <- lr5(data_p_environment)
summary(model_p_environment3)

# Anti environment
# Linear regression
model_a_environment3 <- lr5(data_a_environment)
summary(model_a_environment3) 

# Pro immigration
# Linear regression
model_p_immigration3 <- lr5(data_p_immigration)
summary(model_p_immigration3) 

# Anti immigration
# Linear regression
model_a_immigration3 <- lr5(data_a_immigration)
summary(model_a_immigration3)

# Regression plots
export_summs(model_p_abortion3, model_a_abortion3, model_p_environment3, model_a_environment3, model_p_immigration3, model_a_immigration3, model.names = c('Pro-abortion target', 'Anti-abortion target', 'Pro-environment target', 'Anti-environment target', 'Pro-immigration target', 'Anti-immigration target'), to.file = 'html', scale = TRUE)
```


## EFFECT OF DEMOGRAPHICS
## Gender
```{r non-issue-oriented linear regressions}
## Gender
# Gender on moral legitimacy
summary(moral_gender <- lm(moral_legitimacy ~ gender, data = data, weights = weight_pol)) ## Significant for Male
# Gender on strategic legitimacy
summary(strategic_gender <- lm(strategic_legitimacy ~ gender, data = data, weights = weight_pol)) ## Significant for Male
# Gender on terrorism
summary(terrorism_gender <- lm(terrorism ~ gender, data = data, weights = weight_pol)) ## Significant for Male

# Regression plots
export_summs(moral_gender, strategic_gender, terrorism_gender, model.names = c('Moral legitimacy', 'Strategic legitimacy', 'Terrorism perception'), to.file = 'html', scale = TRUE)

## Race
# Race on moral legitimacy
summary(moral_race <- lm(moral_legitimacy ~ race, data = data, weights = weight_pol)) ## Significant for all
# Race on strategic legitimacy
summary(strategic_race <- lm(strategic_legitimacy ~ race, data = data, weights = weight_pol)) ## Significant for Hispanic and Other
# Race on terrorism
summary(terrorism_race <- lm(terrorism ~ race, data = data, weights = weight_pol)) ## Significant for all

# Regression plots
export_summs(moral_race, strategic_race, terrorism_race, model.names = c('Moral legitimacy', 'Strategic legitimacy', 'Terrorism perception'), to.file = 'html', scale = TRUE)
```

# Gender on moral legitimacy
```{r effect of gender on perceived moral legitimacy of action targeting pro/anti abortion facility}
# Create casualty dataset
data3 <- data

# Create subsetting functions
subset1 <- function(x){
  data1[grepl(x, data1$scenario_type), ]}

subset3 <- function(x){
  data3[grepl(x, data3$scenario_type), ]}

# Create linear regression function
lr6 <- function(x){
  lm(moral_legitimacy ~ gender, data = x, weights = weight_pol)}

## Irrespective of casualties
# Pro abortion
data_p_abortion <- subset1("Pro abortion")
model_p_abortion <- lr6(data_p_abortion)
summary(model_p_abortion) ## Significant for Male

# Anti abortion
data_a_abortion <- subset1("Anti abortion")
model_a_abortion <- lr6(data_a_abortion)
summary(model_a_abortion) ## Not significant

# Regression plots
export_summs(model_p_abortion, model_a_abortion, model.names = c('Pro abortion target', 'Anti abortion target'), to.file = 'html', scale = TRUE)

## Considering casualties
# Pro abortion, no injuries
data_p_abortion_ni <- subset3("Pro abortion, no injuries")
model_p_abortion_ni <- lr6(data_p_abortion_ni)
summary(model_p_abortion_ni) ## Not significant

# Pro abortion, casualties
data_p_abortion_c <- subset3("Pro abortion, casualties")
model_p_abortion_c <- lr6(data_p_abortion_c)
summary(model_p_abortion_c) ## Significant for Male

# Anti abortion, no injuries
data_a_abortion_ni <- subset3("Anti abortion, no injuries")
model_a_abortion_ni <- lr6(data_a_abortion_ni)
summary(model_a_abortion_ni) ## Not significant

# Anti abortion, casualties
data_a_abortion_c <- subset3("Anti abortion, casualties")
model_a_abortion_c <- lr6(data_a_abortion_c)
summary(model_a_abortion_c) ## Not significant
```

# Gender on strategic legitimacy
```{r effect of gender on perceived strategic legitimacy of action targeting pro/anti abortion facility}
# Create linear regression function
lr7 <- function(x){
  lm(strategic_legitimacy ~ gender, data = x, weights = weight_pol)}

## Irrespective of casualties
# Pro abortion
model_p_abortion <- lr7(data_p_abortion)
summary(model_p_abortion) ## Not significant

# Anti abortion
model_a_abortion <- lr7(data_a_abortion)
summary(model_a_abortion) ## Not significant

# Regression plots
export_summs(model_p_abortion, model_a_abortion, model.names = c('Pro abortion target', 'Anti abortion target'), to.file = 'html', scale = TRUE)

## Considering casualties
# Pro abortion, no injuries
model_p_abortion_ni <- lr7(data_p_abortion_ni)
summary(model_p_abortion_ni) ## Not significant

# Pro abortion, casualties
model_p_abortion_c <- lr7(data_p_abortion_c)
summary(model_p_abortion_c) ## Not significant

# Anti abortion, no injuries
model_a_abortion_ni <- lr7(data_a_abortion_ni)
summary(model_a_abortion_ni) ## Not significant

# Anti abortion, casualties
model_a_abortion_c <- lr7(data_a_abortion_c)
summary(model_a_abortion_c) ## Not significant
```

# Gender on terrorism perception
```{r effect of gender of perception as terrorism of action targeting pro/anti abortion facility}
# Create linear regression function
lr8 <- function(x){
  lm(terrorism ~ gender, data = x, weights = weight_pol)}

## Irrespective of casualties
# Pro abortion
model_p_abortion <- lr8(data_p_abortion)
summary(model_p_abortion) ## Not significant

# Anti abortion
model_a_abortion <- lr8(data_a_abortion)
summary(model_a_abortion) ## Not significant

# Regression plots
export_summs(model_p_abortion, model_a_abortion, model.names = c('Pro abortion target', 'Anti abortion target'), to.file = 'html', scale = TRUE)

## Considering casualties
# Pro abortion, no injuries
model_p_abortion_ni <- lr8(data_p_abortion_ni)
summary(model_p_abortion_ni) ## Not significant

# Pro abortion, casualties
model_p_abortion_c <- lr8(data_p_abortion_c)
summary(model_p_abortion_c) ## Not significant

# Anti abortion, no injuries
model_a_abortion_ni <- lr8(data_a_abortion_ni)
summary(model_a_abortion_ni) ## Not significant

# Anti abortion, casualties
model_a_abortion_c <- lr8(data_a_abortion_c)
summary(model_a_abortion_c) ## Not significant
```

## Race
# Race on moral legitimacy
```{r effect of race on perceived moral legitimacy of action targeting a pro/anti immigration facility}
# Create subsetting function
subset6 <- function(x){
  data1[grepl(x, data1$scenario_type), ]}

# Create linear regression function
lr9 <- function(x){
  lm(moral_legitimacy ~ race, data = x, weights = weight_pol)}

## Irrespective of casualties
# Pro immigration
data_p_immigration <- subset6("Pro immigration")
model_p_immigration <- lr9(data_p_immigration)
summary(model_p_immigration) ## Significant for all

# Anti immigration
data_a_immigration <- subset6("Anti immigration")
model_a_immigration <- lr9(data_a_immigration)
summary(model_a_immigration) ## Significant for all

# Regression plots
export_summs(model_p_immigration, model_a_immigration, model.names = c('Pro immigration target', 'Anti immigration target'), to.file = 'html', scale = TRUE)

## Considering casualties
data7 <- data

# Create subsetting function
subset7 <- function(x){
  data7[grepl(x, data7$scenario_type), ]}

# Pro immigration, no injuries
data_p_immigration_ni <- subset7("Pro immigration, no injuries")
model_p_immigration_ni <- lr9(data_p_immigration_ni)
summary(model_p_immigration_ni) ## Significant for Black and Other

# Pro immigration, casualties
data_p_immigration_c <- subset7("Pro immigration, casualties")
model_p_immigration_c <- lr9(data_p_immigration_c)
summary(model_p_immigration_c) ## Significant for all

# Anti immigration, no injuries
data_a_immigration_ni <- subset7("Anti immigration, no injuries")
model_a_immigration_ni <- lr9(data_a_immigration_ni)
summary(model_a_immigration_ni) ## Significant for all

# Anti immigration, casualties
data_a_immigration_c <- subset7("Anti immigration, casualties")
model_a_immigration_c <- lr9(data_a_immigration_c)
summary(model_a_immigration_c) ## Significant for other
```

# Race on strategic legitimacy
```{r effect of race on perceived strategic legitimacy of action targeting pro/anti immigration facility}
# Create linear regression function
lr10 <- function(x){
  lm(strategic_legitimacy ~ race, data = x, weights = weight_pol)}

## Irrespective of casualties
# Pro immigration
model_p_immigration <- lr10(data_p_immigration)
summary(model_p_immigration) ## Not significant

# Anti immigration
model_a_immigration <- lr10(data_a_immigration)
summary(model_a_immigration) ## Significant for Other

# Regression plots
export_summs(model_p_immigration, model_a_immigration, model.names = c('Pro immigration target', 'Anti immigration target'), to.file = 'html', scale = TRUE)

## Considering casualties
# Pro immigration, no injuries
model_p_immigration_ni <- lr10(data_p_immigration_ni)
summary(model_p_immigration_ni) ## Not significant

# Pro immigration, casualties
model_p_immigration_c <- lr10(data_p_immigration_c)
summary(model_p_immigration_c) ## Significant for Other

# Anti immigration, no injuries
model_a_immigration_ni <- lr10(data_a_immigration_ni)
summary(model_a_immigration_ni) ## Significant for Hispanic and Other

# Anti immigration, casualties
model_a_immigration_c <- lr10(data_a_immigration_c)
summary(model_a_immigration_c) ## Not significant
```

# Race on terrorism perception
```{r effect of race on perception as terrorism of action targeting pro/anti immigrantion facility}
# Create linear regression function
lr11 <- function(x){
  lm(terrorism ~ race, data = x, weights = weight_pol)}

## Irrespective of casualties
# Pro immigration
model_p_immigration <- lr11(data_p_immigration)
summary(model_p_immigration) ## Significant for all

# Anti immigration
model_a_immigration <- lr11(data_a_immigration)
summary(model_a_immigration) ## Significant for Black

# Regression plots
export_summs(model_p_immigration, model_a_immigration, model.names = c('Pro immigration target', 'Anti immigration target'), to.file = 'html', scale = TRUE)

## Considering casualties
# Pro immigration, no injuries
model_p_immigration_ni <- lr11(data_p_immigration_ni)
summary(model_p_immigration_ni) ## Significant for all

# Pro immigration, casualties
model_p_immigration_c <- lr11(data_p_immigration_c)
summary(model_p_immigration_c) ## Significant for Other

# Anti immigration, no injuries
model_a_immigration_ni <- lr11(data_a_immigration_ni)
summary(model_a_immigration_ni) ## Not significant

# Anti immigration, casualties
model_a_immigration_c <- lr11(data_a_immigration_c)
summary(model_a_immigration_c) ## Significant for Black and Hispanic
```
